package com.itheima.search.controller;

import com.itheima.search.service.NewsSyncService;
import com.itheima.search.util.EsClearService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用于同步数据处理请求
 * @author NicelYHHello
 */
@RestController
@RequestMapping("/api/sync")
public class SyncController {

    private final NewsSyncService newsSyncService;

    public SyncController(NewsSyncService newsSyncService) {
        this.newsSyncService = newsSyncService;
    }

    /**
     * 数据库全量toES
     * @return
     */
    @PostMapping("/full")
    public String triggerFullSync() {
        try {
            newsSyncService.fullSync();
            return "全量同步已成功触发";
        } catch (Exception e) {
            e.printStackTrace(); // 打印堆栈跟踪到控制台
            return "全量同步失败: " + e.getMessage();
        }
    }

}